#ifndef YUANSHENPLAY_UTIL_H
#define YUANSHENPLAY_UTIL_H

#include <fstream>

inline uint32_t BLEndianUint32(uint32_t value) {
    return ((value & 0x000000FF) << 24) | ((value & 0x0000FF00) << 8) |
           ((value & 0x00FF0000) >> 8) | ((value & 0xFF000000) >> 24);
}

inline uint16_t BLEndianUint16(uint16_t value) {
    return ((value & 0x00FF) << 8) | ((value & 0xFF00) >> 8);
}

template<typename T>
T readFile(std::ifstream &stream) {
    T b;
    stream.read((char *)&b, sizeof(T));
    return b;
}

inline uint16_t readBEndian16(std::ifstream &stream) {
    return BLEndianUint16(readFile<uint16_t>(stream));
}

inline uint32_t readBEndian32(std::ifstream &stream) {
    return BLEndianUint32(readFile<uint32_t>(stream));
}

#endif //YUANSHENPLAY_UTIL_H
